/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$("#chaxtj-ypxs-chaxunbtn").trigger('click'); 
		return false;
		}
	});
});
var kaishisj ='';
var jieshusj = '';
var mingcheng = '';
var yewulx = 1;
var leixing = 1;
//传递初始时间
function getShijian(prekaishisj,prejieshusj){
//查询条件置空
	$('#chaxtj-ypxs-chongzhibtn').click(function(){
		$('#chaxtj-ypxs-xingmingsj').val('');
		$('#ypxs-kaishjsj').val(prekaishisj);
		$('#ypxs-jieshusj').val(prejieshusj);
//		重置后进行查询
		if(prekaishisj!=null){
			$('.chaxtj-clickcontroller-ypxs-input').val(0);
			$('#chaxtj-ypxs-fangshi').val(1);
			$('#lx-ypxsmx').addClass('xuanzong').siblings('li').removeClass('xuanzong');
			$('#lb-quanbu').addClass('xuanzong').siblings('li').removeClass('xuanzong');
			$('#yewulx-quanbu').addClass('xuanzong').siblings('li').removeClass('xuanzong');
			kaishisj =prekaishisj;
			jieshusj = prejieshusj;
			mingcheng = '';
			yewulx = '';
			leixing = '';
			var fscanshu=$('#chaxtj-ypxs-fangshi').val();
			if(fscanshu==1){
				getYpxsMx();
			}else if(fscanshu==2){
				getYpxsHz();
			}
		}
	});
	if(prekaishisj!=null){
		kaishisj =prekaishisj;
		jieshusj = prejieshusj;
		mingcheng = '';
		yewulx = '';
		leixing = '';
		getYpxsMx();
	}
}
	
//点击查询
$('#chaxtj-ypxs-chaxunbtn').click(function(){
	mingcheng = $('#chaxtj-ypxs-xingmingsj').val();
	kaishisj = $('#ypxs-kaishjsj').val();
	jieshusj = $('#ypxs-jieshusj').val();
	yewulx=$('#chaxtj-ypxs-laiyuan').val();
	leixing=$('#chaxtj-ypxs-leixing').val();
	if(yewulx==0){
    	yewulx='';
    }
	if(leixing==0){
    	leixing='';
    }
	var fscanshu=$('#chaxtj-ypxs-fangshi').val();
	if(fscanshu==1){
		getYpxsMx();
	}else if(fscanshu==2){
		getYpxsHz();
	}
	
});
	//业务入口
$(".chaxtj-clickcontroller-ypxs-div ul li").click(function(){
	var bValue = $(this).val();
	$(this).parent().siblings(".chaxtj-clickcontroller-ypxs-input").val(bValue);
	$(this).addClass('xuanzong').siblings('li').removeClass('xuanzong');
	mingcheng = $('#chaxtj-ypxs-xingmingsj').val();
	kaishisj = $('#ypxs-kaishjsj').val();
	jieshusj = $('#ypxs-jieshusj').val();
	yewulx=$('#chaxtj-ypxs-laiyuan').val();
	leixing=$('#chaxtj-ypxs-leixing').val();
	if(yewulx==0){
    	yewulx='';
    }
	if(leixing==0){
    	leixing='';
    }
	var fscanshu=$('#chaxtj-ypxs-fangshi').val();
	if(fscanshu==1){
		getYpxsMx();
	}else if(fscanshu==2){
		getYpxsHz();
	}
});

function getYpxsMx() {
		var totalNumber = 0;
		var params={
				'kaishisj':kaishisj,
		        'jieshusj':jieshusj,
		        'mingcheng':mingcheng,
		        'yewulx':yewulx,
		        'leixing':leixing,
			};
			$.ajax({
			    type:"POST",
			    url:"../chaxuntjypxs/getYpxsmxCount",
			    data:params,
			    async:false,
			    success: function(data){
			    	if(data!=null) {
			    		totalNumber = data;
					}
			    	if(totalNumber==0){ 
						$("#chaxtj-ypxsmxlbnr").css("display","none");
						$("#chaxtj-ypxs-imp").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
					}else{
						$("#chaxtj-ypxsmxlbnr").css("display","block");
						$("#chaxtj-ypxshzlbnr").css("display","none");
						$("#chaxtj-ypxs-imp").html("");
					}
				}
			
			});
		function createYpxsMx(name) {
		  $('#tb-ypxsmx').html('');
		  var container = $('#pagination-'+name);
		  	container.pagination({
		    dataSource:'../chaxuntjypxs/getYpxsMxByPage?kaishisj='+kaishisj+'&jieshusj='+jieshusj+'&mingcheng='+mingcheng+'&yewulx='+yewulx+'&leixing='+leixing,
		    locator: 'entities',
		    pageSize: 12,
		    totalNumber: totalNumber,
		    async:false,
		     //增加总记录数
			showNavigator: true,
	   	    formatNavigator: '共 <%= totalNumber %> 条',
		    callback: function(data, pagination) {
		    	if(data!=null) {
					var content = '';
					$(data).each(function(index,e){
						var yewulx = this.yewulx;
						if(yewulx==1) {
							yewulx = '微诊疗';
						}else if(yewulx==2) {
							yewulx = '售药';
						}else if(yewulx==3) {
							yewulx = '常规门诊';
						} else if(yewulx == 4) {
							yewulx = '库存调整';
						}
						var leixing = this.xiangmulx;
						if(leixing == 1) {
							leixing = '草药';
						}else{
							leixing = '成药';
						}
						//厂商处理
						var changshang;
						if(this.changshang!=null){
							changshang=this.changshang;
						}else{
							changshang='';
						}
						//规格处理
						var guige;
						if(this.guige!=null){
							guige=this.guige;
						}else{
							guige='';
						}
						//销售数量处理
						if(this.shuliang!=null&&this.danwei!=null){
							var shuliang = this.shuliang + this.danwei;
						}else if(this.shuliang!=null){
							var shuliang=this.shuliang;
						}
						content += '<tr>'+
		                '<td width="5%">'+(((pagination.pageNumber-1)*pagination.pageSize)+index+1)+'</td>'+
		                '<td width="15%" class="left">'+this.mingcheng+'</td>'+
		                '<td width="13%">'+guige+'</td>'+
		                '<td width="15%" class="left">'+changshang+'</td>'+
		                '<td width="12%">'+this.xiaoshourq+'</td>'+
		                '<td width="10%">'+yewulx+'</td>'+
		                '<td width="10%">'+leixing+'</td>'+
		                '<td width="10%"">'+shuliang+'</td>'+
		                '<td width="10%">'+parseFloat(this.shoujia).toFixed(2)+'</td>'+
		                '</tr>';
					});
					$('#tb-ypxsmx').html(content);
					
		    	}
		    }
		  });
		  return container;
		}
		createYpxsMx('fenyypxsmx');
		if(totalNumber <= 12) {
			$('#pagination-fenyypxsmx').css('display','none');
		}else{
			$('#pagination-fenyypxsmx').css('display','block');
		}
}
function getYpxsHz() {
		var totalNumber = 0;
		var params={
				'kaishisj':kaishisj,
		        'jieshusj':jieshusj,
		        'mingcheng':mingcheng,
		        'yewulx':yewulx,
		        'leixing':leixing,
			};
			$.ajax({
			    type:"POST",
			    url:"../chaxuntjypxs/getYpxsHzCount",
			    data:params,
			    async:false,
			    success: function(data){
			    	if(data!=null) {
			    		totalNumber = data;
					}
			    	if(totalNumber==0){ 
						$("#chaxtj-ypxshzlbnr").css("display","none");
						$("#chaxtj-ypxs-imp").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
					}else{
						$("#chaxtj-ypxshzlbnr").css("display","block");
						$("#chaxtj-ypxsmxlbnr").css("display","none");
						$("#chaxtj-ypxs-imp").html("");
					}
				}
			
			});
		function createYpxsHz(name) {
		  $('#tb-ypxshz').html('');
		  var container = $('#pagination-'+name);
		  	container.pagination({
		    dataSource:'../chaxuntjypxs/getYpxsHzByPage?kaishisj='+kaishisj+'&jieshusj='+jieshusj+'&mingcheng='+mingcheng+'&yewulx='+yewulx+'&leixing='+leixing,
		    locator: 'entities',
		    pageSize: 12,
		    totalNumber: totalNumber,
		    async:false,
		     //增加总记录数
			showNavigator: true,
	   	    formatNavigator: '共 <%= totalNumber %> 条',
		    callback: function(data, pagination) {
		    	if(data!=null) {
					var content = '';
					$(data).each(function(index,e){
						var yewulx = this.yewulx;
						if(yewulx==1) {
							yewulx = '微诊疗';
						}else if(yewulx==2) {
							yewulx = '售药';
						}else if(yewulx==3) {
							yewulx = '常规门诊';
						}else if(yewulx == 4) {
							yewulx = '库存调整';
						}
						var leixing = this.xiangmulx;
						if(leixing == 1) {
							leixing = '草药';
						}else{
							leixing = '成药';
						}
						//厂商处理
						var changshang;
						if(this.changshang!=null){
							changshang=this.changshang;
						}else{
							changshang='';
						}
						//规格处理
						var guige;
						if(this.guige!=null){
							guige=this.guige;
						}else{
							guige='';
						}
						//销售数量处理
						if(this.shuliang!=null&&this.danwei!=null){
							var shuliang = this.shuliang + this.danwei;
						}else if(this.shuliang!=null){
							var shuliang=this.shuliang;
						}
						content += '<tr>'+
		                '<td width="5%">'+(((pagination.pageNumber-1)*pagination.pageSize)+index+1)+'</td>'+
		                '<td width="15%" class="left">'+this.mingcheng+'</td>'+
		                '<td width="15%">'+guige+'</td>'+
		                '<td width="17%" class="left">'+changshang+'</td>'+
		                '<td width="11%">'+yewulx+'</td>'+
		                '<td width="11%">'+leixing+'</td>'+
		                '<td width="13%"">'+shuliang+'</td>'+
		                '<td width="13%">'+parseFloat(this.shoujia).toFixed(2)+'</td>'+
		                '</tr>';
					});
					$('#tb-ypxshz').html(content);
					
		    	}
		    }
		  });
		  return container;
		}
		createYpxsHz('fenyypxshz');
		if(totalNumber <= 12) {
			$('#pagination-fenyypxshz').css('display','none');
		}else{
			$('#pagination-fenyypxshz').css('display','block');
		}
}